
#include "CoordinatorUnWraper.h"

CoordinatorUnWraper::CoordinatorUnWraper() {
	itsCoordinator = NULL;
}

CoordinatorUnWraper::~CoordinatorUnWraper() {
}


void CoordinatorUnWraper::setExecutor(void * executor)
{
	itsCoordinator = reinterpret_cast<Coordinator*>(executor);
}

std::string CoordinatorUnWraper::serv(const std::string& messege)
{
	std::string strRet;
	std::stringstream ss(messege);
	std::stringstream ssRet;
	int x;
	ss>>x;
	MESSAGE_TYPE msgType = (MESSAGE_TYPE) x;
	AliveMsg aliveMsg;
	AliveRet aliveRet;
	TaskRegistration taskReg;
	TaskRegistrationRet taskRegRet;
	TaskStatusChange taskSC;
	Message msg;
	switch(msgType)
	{
	case ALIVE:
		aliveMsg.deSerialize(ss);
		aliveRet = itsCoordinator->alive(aliveMsg);
		aliveRet.serialize(ssRet);
		strRet = ssRet.str();
		break;
	case TASK_REGISTRATION:
		taskReg.deSerialize(ss);
		taskRegRet = itsCoordinator->registerTask(taskReg);
		taskRegRet.serialize(ssRet);
		strRet = ssRet.str();
		break;
	case TASK_STATUS_CHANGE:
		taskSC.deSerialize(ss);
		itsCoordinator->changeTaskStatus(taskSC);
		msg.serialize(ssRet);
		strRet = ssRet.str();
		break;
	case NUMBER_OF_TASKS:
		itsCoordinator->getNumberOfTasks().serialize(ssRet);
		strRet = ssRet.str();
	}

	return strRet;
}
/*********************************************************************
	File Path	: DefaultComponent\DefaultConfig\CoordinatorUnWraper.cpp
*********************************************************************/
